﻿// 2025/10/20: 首个版本
// 2025/11/12: 优化tab control显示

using System;
using Avalonia;
using Avalonia.Controls;
using ASEva;
using ASEva.UIAvalonia;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
using System.Linq;
using ASEva.Utility;

namespace CommonSource
{
    partial class CommonPickOptionsControl : Panel
    {
        public CommonPickOptionsControl()
        {
            InitializeComponent();
            language = new LanguageSwitch(Resources, AgencyLocal.GetAppLanguage());

            model = new CommonPickOptionsControlViewModel();
            DataContext = model;
        }

        public CommonPickOptions Options => model.Result;

        public bool WithEventFilter
        {
            set => model.WithEventFilter = value;
        }

        private LanguageSwitch language;
        private CommonPickOptionsControlViewModel model;
    }

    partial class CommonPickOptionsControlViewModel : ObservableObject
    {
        [ObservableProperty]
        private ObservableCollection<bool> busChannelsFilter = new ObservableCollection<bool>(new bool[ChannelNumber.Bus].Populate(i => true));

        [ObservableProperty]
        private ObservableCollection<bool> videoChannelsFilter = new ObservableCollection<bool>(new bool[ChannelNumber.Video].Populate(i => true));

        [ObservableProperty]
        private bool audioFilter = true;

        [ObservableProperty]
        private bool signalFilter = true;

        [ObservableProperty]
        private bool sampleFilter = true;

        [ObservableProperty]
        private bool matrixFilter = true;

        [ObservableProperty]
        private bool withEventFilter = true;

        [ObservableProperty]
        private bool eventFilter = true;

        public CommonPickOptions Result
        {
            get
            {
                var options = new CommonPickOptions();
                options.BusChannelFilter = BusChannelsFilter.ToArray();
                options.VideoChannelFilter = VideoChannelsFilter.ToArray();
                options.AudioFilter = AudioFilter;
                options.SignalFilter = SignalFilter;
                options.SampleFilter = SampleFilter;
                options.MatrixFilter = MatrixFilter;
                options.EventFilter = WithEventFilter ? EventFilter : false;
                return options;
            }
        }
    }
}